#!/bin/bash
declare -a cydia
cydia=($CYDIA)

chown root:wheel /var/mobile/Library/SBSettings/Toggles/NoCyfresh/Cydia.mod
chmod 6775 /var/mobile/Library/SBSettings/Toggles/NoCyfresh/Cydia.mod
chown root:wheel /var/mobile/Library/SBSettings/Toggles/NoCyfresh/nocyfreshhelper
chmod 6775 /var/mobile/Library/SBSettings/Toggles/NoCyfresh/nocyfreshhelper
chown root:mobile /var/mobile/Library/SBSettings/Toggles/NoCyfresh/Toggle.dylib
chmod 775 /var/mobile/Library/SBSettings/Toggles/NoCyfresh/Toggle.dylib

if [ ! -f /Applications/Cydia.app/Cydia.bak ]
then
	cp /Applications/Cydia.app/Cydia /Applications/Cydia.app/Cydia.bak
fi

rm -f /Applications/Cydia.app/Cydia
cp -f /var/mobile/Library/SBSettings/Toggles/NoCyfresh/Cydia.mod /Applications/Cydia.app/Cydia

if [[ $1 == install ]]; then
    if [[ ${CYDIA+@} ]]; then
        eval "echo 'finish:restart' >&${cydia[0]}"
    fi
elif [[ $1 == upgrade ]]; then
    if [[ ${CYDIA+@} ]]; then
        eval "echo 'finish:restart' >&${cydia[0]}"
    fi
fi
exit 0
